﻿using System.ComponentModel;

namespace InputBoxes.Controls
{
    public class ParsingValueTypeInputBoxBase<T> : ParsingInputBoxBase
        where T : struct
    {
        protected virtual T? Parse(string text)
        {
            return null;
        }

        [Browsable(false)]
        public T Value
        {
            get { return (T)UntypedValue; }
            set { SetUntypedValue(value); }
        }

        [Browsable(false)]
        public T? NullableValue
        {
            get
            {
                object untypedValue = UntypedValue;
                if (untypedValue == null) return null;
                if (untypedValue is T) return (T)untypedValue;
                return null;
            }
        }
    }
}